<?php

namespace app\order\logic;

use app\data\util\HttpUtil;
use think\facade\Db;
use think\facade\Cache;
use think\exception\ValidateException;
use think\facade\Log;
use util\Token;
use util\Upload;

use app\common\library\Excel;
use app\data\util\MqQueueName;
use app\systems\logic\MqTaskPushLogic;

class OrderReportReamazeLogic
{
    protected $model = null;
    public function __construct()
    {
        $this->model = new \app\order\model\OrderCheck();
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 列表
     * @author zhangheng
     */
    public function index($params = [])
    {
        $create_time = $params['create_time'] ?? [];
        $limit = $params['limit'] ?? 10;
        $where = [];

        if (!empty($create_time)) {
            $where[]  = ['timedate', '>=', strtotime($create_time[0])];
            $where[]  = ['timedate', '<=', strtotime($create_time[1]) + 3600*24-1];
        }

        $list = Db::name('report_reamaze')
            ->where($where)
            ->order("create_time desc")
            ->paginate($limit);

        $lists = $list->items();
        // foreach ($lists as $k=>$v) {
        //     $lists[$k]['date'] = date('Y-m', $v['timedate']);
        // }
                
        $data = [
            'list' => $lists,
            'total' => $list->total(),
        ];
        return json(DefaultResponse(200, true, '获取成功', $data));
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 导出
     * @author zhangheng
     */
    public function export($params = [])
    {
        $lists = [];
        $header = [];
        $header[] = ['月份', 'date'];
        $header[] = ['支付类型', 'type'];
        $header[] = ['转单号码', 'transfer_number'];
        $header[] = ['金额', 'cost'];
        $fileName = "export_Advaccount" . time();
        return Excel::exportData($lists, $header, $fileName, 'xlsx');
    }

}
